
import {
  bookCategoryList
} from "../../../utils/commondata.js";

import {
  request
} from "../../../utils/request.js";
import regeneratorRuntime from '../../../utils/runtime';

var appInst =  getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    mainColor:appInst.globalData.mainColor,
    bookInfo:{},
    bookName:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let pages = getCurrentPages();
    let currentPage = pages[pages.length - 1];
    let options = currentPage.options;
    const { bookId,bookName } = options;
    this.setData({
      bookName
    });
    this.loadBookInfo(bookId);
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  /**
   * ti
   * @param {*} e 
   */
  handleDetailChapter(e){
    let {id} = e.currentTarget.dataset;
    wx.navigateTo({
      url:'/pages/chapter/detail/index?contentType=ancient_book&leftFlag=true&chapterId=' + id,
    });
  },

  /**
   * 加载课本明细
   * @param {*} id 
   */
  async loadBookInfo(id){
    const res = await request({
      url: "/book/detail?bookId=" + id,
      method: "get"
    });
    if(res.code != 0){
      return;
    }
    this.setData({
      bookInfo:res.data,
    });

  },

})